package com.plugin.manage.test;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;

@Service
public class AppDeepseek {

    public String chatWithDeepseek(String message) {

        try  {

            CloseableHttpClient httpClient = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost("http://localhost:1234/v1/chat/completions");
            httpPost.setHeader("Content-Type", "application/json");

            // 构建OpenAI兼容格式请求体
            String jsonBody = String.format("{\"model\":\"deepseek-r1-distill-qwen-1.5b\","
                    + "\"messages\":[{\"role\":\"user\",\"content\":\"%s\"}]}", message);
            System.out.println(jsonBody.toString());
            httpPost.setEntity(new StringEntity(jsonBody));

            CloseableHttpResponse response = httpClient.execute(httpPost);
            System.out.println(response.getEntity().getContent());
            return EntityUtils.toString(response.getEntity());

        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }


}
